import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/', name: 'Manage', component: () => import('../views/Manage'),
    redirect:"/login",
    children:[
      {path: 'home', name: 'Home', component: () => import('../views/Home')},
      {path: 'meat', name: 'Meat', component: () => import('../views/Meat')},
      {path: 'earnView', name: 'EarnView', component: () => import('../views/EarnView')},
      {path: 'vegetable', name: 'Vegetable', component: () => import('../views/Vegetable')},
      {path: 'orderDetail', name: 'OrderDetail', component: () => import('../views/OrderDetail')},
      {path: 'user', name: 'User', component: () => import('../views/User')},
      {path: 'warehouse', name: 'Warehouse', component: () => import('../views/Warehouse')},
      {path: 'verify', name: 'Verify', component: () => import('../views/Verify')},
      {path: 'seafood', name: 'Seafood', component: () => import('../views/Seafood')},
      {path: 'message', name: 'Message', component: () => import('../views/Message')},
    ]
  },
  {path: '/login',
    name: 'Login',
    component: () => import('../views/Login')
  },

  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue')
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

router.beforeEach((to, from, next) => {
  console.log("显示具体包含了什么，包括隐藏的特殊字符",JSON.stringify(to.path));
  if (to.path == '/login' || to.path == '/register') {

    next();
  } else {
    let token = sessionStorage.getItem('token');
    if (token == null || token == '' ||token==undefined) {
      console.log("进来了");
      next('/login');
    } else {
      next();
    }
  }
    });



